﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace DataAccess
{

    public class FacultyDAO
    {
        ConnectionDatabase conn;
        SqlCommand cmd;
        SqlDataReader dr;
        public FacultyDAO()
        {
            conn = new ConnectionDatabase();
        }
        // nấy ra code Subjects
        public string CodeFaculty(string NameFaculty)
        {
            string Faculty=null;
            SqlConnection con = conn.GetConnection();
            try
            {
                con.Open();
                cmd = new SqlCommand("SP_CodeFaculty", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add("@NameFaculty", SqlDbType.VarChar).Value = NameFaculty;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    Faculty = dr.GetString(0);
                    return Faculty;
                }
                else
                {

                    return Faculty;
                }
            }
            catch (Exception e) { throw; }
            finally { con.Close(); }

        }
        public DataTable ShowFaculty()
        {
            DataTable tbl = conn.ExecuteQueryDataTable("select * from Faculty");
            return tbl;
        }
    }
}
